using System;
using System.Collections.Generic;
using WindowsPhoneEssentials.Storage;

namespace WindowsPhoneMVC.Tests.Phone.State.Fakes
{
    public class FakeTransientStore : IStorageProvider 
    {
        private readonly Dictionary<string, object> store = new Dictionary<string, object>();

        public Dictionary<string, object> Store
        {
            get { return store; }
        }

        public void Save<T>(string key, T obj) where T : class
        {
            if (Store.ContainsKey(key))
                Store[key] = obj;
            else
                Store.Add(key, obj);
        }

        public T Load<T>(string key) where T : class
        {
            if (Store.ContainsKey(key))
                return (T)Store[key];
            return default(T);
        }

        public bool Contains(string key)
        {
            return Store.ContainsKey(key);
        }

        public void Remove(string key)
        {
            if (Store.ContainsKey(key))
                Store.Remove(key);
        }
    }
}